﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;

using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace Mentrixmax.Controles
{
    public partial class ComboCustomEnum : ComboBox
    {
        private Type PEnum;
        public Type Enumerator
        {
            get { return PEnum; }
            set
            {
                PEnum = value;
                if (value != null)
                {
                    initial();
                }
            }
        }

        public void Clear()
        {
            this.SelectedIndex = -1;
        }
        private bool PIgnoraPrimeiro;

        public bool IgnoraPrimeiro
        {
            get { return PIgnoraPrimeiro; }
            set { PIgnoraPrimeiro = value; }
        }

        
        private void initial()
        {
            this.DropDownStyle = ComboBoxStyle.DropDownList;
            this.ValueMember = "Key";
            this.DisplayMember = "Value";
            ArrayList lista = (ArrayList)Menfram.Common.Constantes.ConstantesEnum.Listar(Enumerator);
            if (IgnoraPrimeiro)
            {
                lista.RemoveAt(0);
            }
            DataSource = lista;
        }
        public ComboCustomEnum()
        {
            InitializeComponent();
            
        }
        public MentrixmaxFormularios.FormsAbstratos.FrmPaiInterface Pai { get; set; }
        private void FormularioEditavel() {

            if (this.Pai != null)
            {
                this.Pai.NovoRegistro = true;
                this.Pai.HabilitarCampos(this, new EventArgs());
            }
            if (this.Pesquisa != null) {
                this.Pesquisa.realizaEvento();
            }
        }
        protected override void OnKeyUp(KeyEventArgs e)
        {
            base.OnKeyUp(e);
            FormularioEditavel();
            
        }

        protected override void OnDropDownClosed(EventArgs e)
        {
            base.OnDropDownClosed(e);
            FormularioEditavel();
        }

       
        private MentrixmaxFormularios.FrGeralCinzaClaro PPesquisa;

        public MentrixmaxFormularios.FrGeralCinzaClaro Pesquisa
        {
            get { return PPesquisa; }
            set { PPesquisa = value; }
        }


        public ComboCustomEnum(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }
    }
}
